<?

define('ROOT_PATH', '/var/www/vhosts/mc-kurzurlaub.net/httpdocs/lisa-kit/client/' );
include(ROOT_PATH . 'common.php');
define('PAGE_CLIENT', 'charts.php' );


$parts = split('/', $_GET['path']);
$request_mode = $parts[0];
$request_string = $parts[1];

include(ROOT_PATH . 'includes/header.php');

if($_POST['send'] == 1){
	
	unset($_POST['dropdown_facebook'], $_POST['dropdown_twitter']);
	
	$company_name = urlencode($_POST['company_name']);//'lufthansa';
	$url_info = URL . 'info/' . $company_name . '/';
				
	$ch = curl_init();
	curl_setopt($ch, CURLOPT_URL, $url_info);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
	$content = curl_exec($ch);
	
	curl_close($ch);

	$content = str_replace('smg:', '', $content);
	$content = str_replace('rdf:', '', $content);
	$content = str_replace('cd:', '', $content);
	
	$xml = simplexml_load_string($content);
	foreach($xml->Description->facebook->Bag->li as $row){
		$facebook_array[] = (string)$row;
	}

	$xml = simplexml_load_string($content);
	foreach($xml->Description->twitter->Bag->li as $row){
		$twitter_array[] = (string)$row;
	}
	
	unset($first);
	$facebook_dropdown = '<select name="dropdown_facebook" onChange="MM_jumpMenu(\'facebook\',this,0)">';
	foreach($facebook_array as $row){
		$first = (!isset($first) ) ? $row : $first;
		$selected = ($row == $_POST['dropdown_facebook']) ? 'selected' : '';
		$facebook_dropdown .= '<option value="' . $row . '"' . $selected . '>' . $row . '</option>';
	}
	$facebook_dropdown .= '</select>';
	$facebook_page_name = ($_POST['dropdown_facebook'] != '') ? $_POST['dropdown_facebook'] : $first;
	



	unset($first);
	$twitter_dropdown = '<select name="dropdown_twitter" onChange="MM_jumpMenu(\'twitter\',this,0)">';
	foreach($twitter_array as $row){
		$first = (!isset($first) ) ? $row : $first;
		$selected = ($row == $_POST['dropdown_facebook']) ? 'selected' : '';
		$twitter_dropdown .= '<option value="' . $row . '" ' . $selected . '>' . $row . '</option>';
	}
	$twitter_dropdown .= '</select>';
	$twitter_page_name = ($_POST['dropdown_twitter'] != '') ? $_POST['dropdown_twitter'] : $first;


	if(count($facebook_array) > 0){
		$url_frame_facebook = PAGE_CLIENT . '?type=facebook_timeline&url=' . URL . 'facebook/' . urlencode($facebook_page_name) . '/';
		$url_frame_facebook_posts = PAGE_CLIENT . '?type=facebook_posts&url=' . urlencode( URL . 'facebook/' . $facebook_page_name . '/' );
		$url_frame_facebook_likes = PAGE_CLIENT . '?type=facebook_likes&url=' .  urlencode( URL . 'facebook/' . $facebook_page_name . '/' );
		$url_frame_facebook_comments = PAGE_CLIENT . '?type=facebook_comments&url=' .  urlencode( URL . 'facebook/' . $facebook_page_name . '/' );
	}
	else{
		$url_frame_facebook = PAGE_CLIENT . '?type=blank';
		$url_frame_facebook_posts = PAGE_CLIENT . '?type=blank';
		$url_frame_facebook_likes = PAGE_CLIENT . '?type=blank';
		$url_frame_facebook_comments = PAGE_CLIENT . '?type=blank';
	}
	
	if(count($twitter_array) > 0){
		$url_frame_twitter = PAGE_CLIENT . '?type=twitter_timeline&url=' . URL . 'twitter/' . $twitter_page_name . '/';
		$url_frame_twitter_days = PAGE_CLIENT . '?type=twitter_days&url=' . URL . 'twitter/' . $twitter_page_name . '/';
	}
	else{
		$url_frame_twitter = PAGE_CLIENT . '?type=blank';
		$url_frame_twitter_days = PAGE_CLIENT . '?type=blank';
	}

}

?>

<script type="text/javascript">
function MM_jumpMenu(targ,selObj,restore){ //v3.0

  f_waiting(targ,selObj,restore);

  eval("document.getElementById('frame_" + targ + "').src='<?=PAGE_CLIENT . '?type='?>" + targ + "<?='_timeline&url=' . URL ?>" + targ + "<?='/'?>"+selObj.options[selObj.selectedIndex].value+"<?='/'?>'");
  if(targ == 'facebook'){
  	eval("document.getElementById('frame_" + targ + "_posts').src='<?=PAGE_CLIENT . '?type=facebook_posts&url=' . URL ?>" + targ + "<?='/'?>"+selObj.options[selObj.selectedIndex].value+"<?='/'?>'");
  	eval("document.getElementById('frame_" + targ + "_likes').src='<?=PAGE_CLIENT . '?type=facebook_likes&url=' . URL ?>" + targ + "<?='/'?>"+selObj.options[selObj.selectedIndex].value+"<?='/'?>'");
  	eval("document.getElementById('frame_" + targ + "_comments').src='<?=PAGE_CLIENT . '?type=facebook_comments&url=' . URL ?>" + targ + "<?='/'?>"+selObj.options[selObj.selectedIndex].value+"<?='/'?>'");
  }
  if(targ == 'twitter'){
  	eval("document.getElementById('frame_" + targ + "_days').src='<?=PAGE_CLIENT . '?type=twitter_days&url=' . URL ?>" + targ + "<?='/'?>"+selObj.options[selObj.selectedIndex].value+"<?='/'?>'");
  }
  eval("document.getElementById('label_" + targ + "').value='" + selObj.options[selObj.selectedIndex].value + "'");
  if (restore) selObj.selectedIndex=0;
}

function f_waiting(targ,selObj,restore){

  eval("document.getElementById('frame_" + targ + "').src='<?=PAGE_CLIENT . '?type=waiting'?>'");
  if(targ == 'facebook'){
  	eval("document.getElementById('frame_" + targ + "_posts').src='<?=PAGE_CLIENT . '?type=waiting'?>'");
  	eval("document.getElementById('frame_" + targ + "_likes').src='<?=PAGE_CLIENT . '?type=waiting'?>'");
  	eval("document.getElementById('frame_" + targ + "_comments').src='<?=PAGE_CLIENT . '?type=waiting'?>'");
  }
  if(targ == 'twitter'){
  	eval("document.getElementById('frame_" + targ + "_days').src='<?=PAGE_CLIENT . '?type=waiting'?>'");
  }
}


</script>

<table width="1000" border="0">
  <tr>
    <td align="left" valign="top"><table width="400" cellpadding="2" cellspacing="2">
      <tr>
        <td colspan="3" style="background-color:#ECECEC; border:1px dashed #FFF;" ><strong>Summary</strong></td>
        </tr>
      <tr>
        <td style="background-color:#ECECEC; border:1px dashed #FFF;" colspan="2">Search item</td>
        <td style="background-color:#ECECEC; border:1px dashed #FFF;" width="71%"><?=$company_name?></td>
      </tr>
      <tr>
        <td style="background-color:#ECECEC; border:1px dashed #FFF;" width="16%" rowspan="2">Hits</td>
        <td style="background-color:#ECECEC; border:1px dashed #FFF;" width="13%"><label for="textfield4">Facebook</label></td>
        <td style="background-color:#ECECEC; border:1px dashed #FFF;"><input style="border:0px; background-color:#ECECEC;" type="text" name="label_facebook" id="label_facebook" value="<?=$facebook_page_name?>" /></td>
      </tr>
      <tr>
        <td style="background-color:#ECECEC; border:1px dashed #FFF;"><label for="textfield5">Twitter</label></td>
        <td style="background-color:#ECECEC; border:1px dashed #FFF;"><input style="border:0px; background-color:#ECECEC;" type="text" name="label_twitter" id="label_twitter" value="<?=$twitter_page_name?>" /></td>
      </tr>
    </table></td>
    <td align="right" valign="top"><form action="?" method="post" name="form1" id="form1"><table width="400" cellpadding="2" cellspacing="2">
      <tr>
        <td  style="background-color:#ECECEC; border:1px dashed #FFF;"><strong>Search for other items</strong></td>
      </tr>
      <tr>
        <td  style="background-color:#ECECEC; border:1px dashed #FFF;" align="right">
          <label for="textfield3"></label>
          <input type="text" name="company_name" id="company_name" size="40" />
          <input type="hidden" name="send" value="1" />
        </td>
      </tr>
      <tr>
        <td  style="background-color:#ECECEC; border:1px dashed #FFF;" align="right"><input type="submit" name="button" id="button" value="New Search" /></td>
      </tr>
    </table></form></td>
  </tr>
</table>
<p><a href="http://twitter.com/" target="_blank"></a></p>
<p><a href="http://facebook.com/" target="_blank"><br />
  <img src="Header/images/facebook.jpeg"/></a><a href="http://twitter.com/" target="_blank"></a>
  <?=$facebook_dropdown?>
  <BR>
</p>
<table width="1000" height="400" border="0" cellspacing="0" cellpadding="0" style="padding:0px; margin:0px;">
  <tr>
    <td width="500" height="400"><iframe scrolling="no" name="frame_facebook" frameborder="0" id="frame_facebook" src="<?=$url_frame_facebook?>" width="500" height="400"></iframe></td>
    <td width="500" height="400">

        <table width="500" border="0" cellspacing="0" cellpadding="0" style="padding:0px; margin:0px;">
          <tr>
            <td width="250" height="200" valign="top" style="vertical-align:text-top;"><iframe scrolling="no" name="frame_facebook_posts" frameborder="0" id="frame_facebook_posts" src="<?=$url_frame_facebook_posts?>" width="250" height="200"></iframe></td>
            <td width="250" height="200" valign="top"><iframe scrolling="no" name="frame_facebook_likes" frameborder="0" id="frame_facebook_likes" src="<?=$url_frame_facebook_likes?>" width="250" height="200"></iframe></td>
          </tr>
          <tr>
            <td width="250"><iframe scrolling="no" name="frame_facebook_comments" frameborder="0" id="frame_facebook_comments" src="<?=$url_frame_facebook_comments?>" width="250" height="200"></iframe></td>
            <td width="250" height="200">&nbsp;</td>
          </tr>
        </table>
    
    </td>
  </tr>
</table><BR />




<BR><BR>
<a href="http://twitter.com/" target="_blank"><img src="Header/images/twitter.jpeg"/></a>
<?=$twitter_dropdown?>
<BR>
<table width="1000" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td><iframe scrolling="no" name="frame_twitter" frameborder="0" id="frame_twitter" src="<?=$url_frame_twitter?>" width="500" height="400"></iframe></td>
    <td><iframe scrolling="no" name="frame_twitter_days" frameborder="0" id="frame_twitter_days" src="<?=$url_frame_twitter_days?>" width="500" height="400"></iframe></td>
  </tr>
</table>
<?

include(ROOT_PATH . 'includes/footer.php');
?>
